#include "comm.h"
using namespace std;

int main()
{
    Fifo fifo(Path);
    // 读端

    // 1.打开文件
    int rfd = open(Path, O_RDONLY);
    if (rfd < 0)
    {
        cerr << "open failed, errno: " << errno << ", errstring: " << strerror(errno) << endl;
        return 1;
    }


    // 2.读文件
    char ch[1024];
    while (1)
    {
        ssize_t n = read(rfd, ch, sizeof(ch)-1);
        if (n > 0)
        {
            ch[n] = 0;
            cout << "read success,say:"<< ch << endl;
        }
        else if(n == 0)
        {
            cout << "read endof file" << endl;
            break;
        }
        else
        {
            cout << "read fail"<< " "<< "errno:" << errno << "errorstring:" << strerror(errno) << endl;
            break;
        }
    }
    close(rfd);
    return 0;
}